﻿<!--#include file="conn.asp"#-->
<!--#include file="sessao.asp"#-->
<!--#include file="getsessao.asp"#-->
<!--#include file="fn_multiselect.asp"#-->
<!--#include file="fn_combo.asp"#-->
<!--#include file="fn_table.asp"#-->
<%

Select Case request("acao")
	Case "getRegional"
		getRegional()
	Case "getRegionalUF"
		getRegionalUF()
	Case "getRegionalUFDDD"
		getRegionalUFDDD()
	Case "setRegional"
		setRegional()
	Case "getUF"
		getUF()
	Case "setUF"
		setUF()
	Case "getDDD"
		getDDD()
	Case "setDDD"
		setDDD()
	Case "getArea"
		getArea()
	Case "setArea"
		setArea()	
	Case "getCargo"
		getCargo()
	Case "setCargo"
		setCargo()
	Case "getComunicados"
		getComunicados()
	Case "getStatus"
		getStatus()
End Select

Sub getStatus()
	Dim db_string
	db_string = " select a.cod_status_informativo,a.desc_status_informativo,0 as selected from informativos.tb_status_informativo as a "
	db_string = db_string & " order by a.desc_status_informativo "
	retorno  = fn_combo(db_string,true,"")
	response.write retorno
End Sub


Sub getRegional()
	Dim db_string 
	db_string = "select reg.cod_regional,reg.sigla_regional,case when isnull(rp.cod_usuario,0) <> 0 then 'checked' else '' end as checked from informacao.tb_regionais as reg"
	db_string = db_string & " left outer join informacao.tb_usuario_regional_form as rp "
	db_string = db_string & " on rp.cod_usuario="&vcod_usuario&" and rp.cod_form=2 and rp.cod_regional=reg.cod_regional "
	db_string = db_string & " order by reg.sigla_regional "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub

Sub getRegionalUF()
	Dim db_string
	db_string = "select distinct uf.cod_uf,uf.uf,case when isnull(uff.cod_usuario,0) <> 0 then 'checked' else '' end as checked from informacao.tb_ufs as uf "
	db_string = db_string & " inner join informacao.tb_regional_uf as ruf on ruf.cod_uf=uf.cod_uf and ruf.cod_regional in("&request("ids")&") "
	db_string = db_string & " left outer join informacao.tb_usuario_uf_form as uff "
	db_string = db_string & " on uff.cod_usuario="&vcod_usuario&" and uff.cod_form=2 and uf.cod_uf=uff.cod_uf "
	db_string = db_string & " order by uf.uf "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub


Sub getUF()
	Dim db_string
	db_string = "select uf.cod_uf,uf.uf,case when isnull(uff.cod_usuario,0) <> 0 then 'checked' else '' end as checked from informacao.tb_ufs as uf "
	db_string = db_string & " left outer join informacao.tb_usuario_uf_form as uff "
	db_string = db_string & " on uff.cod_usuario="&vcod_usuario&" and uff.cod_form=2 and uf.cod_uf=uff.cod_uf "
	db_string = db_string & " order by uf.uf "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub

Sub getDDD()
	Dim db_string
	db_string = "select ddd.cod_ddd,ddd.ddd,case when isnull(dddu.cod_usuario,0) <> 0 then 'checked' else '' end as checked from informacao.tb_ddds as ddd "
	db_string = db_string & " left outer join informacao.tb_usuario_ddd_form as dddu "
	db_string = db_string & " on dddu.cod_usuario="&vcod_usuario&" and dddu.cod_form=2 and dddu.cod_ddd=ddd.cod_ddd "
	db_string = db_string & " order by ddd.ddd "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub

Sub getRegionalUFDDD()
	Dim db_string
	db_string = "select distinct ddd.cod_ddd,ddd.ddd,case when isnull(dddu.cod_usuario,0) <> 0 then 'checked' else '' end as checked from informacao.tb_ddds as ddd "
	db_string = db_string & " inner join informacao.tb_regional_uf_ddd as ruddd on ddd.cod_ddd=ruddd.cod_ddd "
	if request("idregs") <> "" then
		db_string = db_string & " and ruddd.cod_regional in("&request("idregs")&")"
	end if
	if request("idufs") <> "" then
		db_string = db_string & " and ruddd.cod_uf in("&request("idufs")&")"
	end if
	db_string = db_string & " left outer join informacao.tb_usuario_ddd_form as dddu "
	db_string = db_string & " on dddu.cod_usuario="&vcod_usuario&" and dddu.cod_form=2 and dddu.cod_ddd=ddd.cod_ddd "
	db_string = db_string & " order by ddd.ddd "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub

Sub getArea()
	Dim db_string
	db_string = " select a.cod_area,a.desc_area,case when isnull(ua.cod_area,0) <> 0 then 'checked' else '' end as selected from informacao.tb_areas as a "
	db_string = db_string & " left outer join informacao.tb_usuario_area_form as ua "
	db_string = db_string & " on ua.cod_usuario="&vcod_usuario&" and ua.cod_form=2 and ua.cod_area=a.cod_area "
	db_string = db_string & " where a.cod_status_area=1 "
	db_string = db_string & " order by a.desc_area "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub

Sub getCargo()
	Dim db_string
	db_string = " select a.cod_cargo,a.desc_cargo,case when isnull(ua.cod_cargo,0) <> 0 then 'checked'  else '' end as checked from informacao.tb_cargos as a "
	db_string = db_string & " left outer join informacao.tb_usuario_cargo_form as ua "
	db_string = db_string & " on ua.cod_usuario="&vcod_usuario&" and ua.cod_form=2 and ua.cod_cargo=a.cod_cargo "
	db_string = db_string & " where a.cod_status_cargo=1 "
	db_string = db_string & " order by a.desc_cargo "
	retorno  = fn_multiselect(db_string,request("nome"))
	response.write retorno
End Sub

Sub setRegional()
	Dim db_string
	if trim(request("ids")) <> "" then
		db_string = "delete informacao.tb_usuario_regional_form where cod_usuario="&vcod_usuario&" and cod_form=2;"
		db_string = db_string & "insert into informacao.tb_usuario_regional_form("
		db_string = db_string & "cod_usuario,"
		db_string = db_string & "cod_regional,"
		db_string = db_string & "cod_form "
		db_string = db_string & ") ("
		db_string = db_string & " select "&vcod_usuario&","
		db_string = db_string & " cod_regional,"
		db_string = db_string & " 2 as cod_form "
		db_string = db_string & " from informacao.tb_regionais "
		db_string = db_string & " where cod_regional in("&request("ids")&")"
		db_string = db_string & ")"
		executeQuery(db_string)
	else
		db_string = "delete informacao.tb_usuario_regional_form where cod_usuario="&vcod_usuario&" and cod_form=2;"
		executeQuery(db_string)
	End if
	response.write "{success : true,data :{}}"
End Sub

Sub setUF()
	Dim db_string
	if trim(request("ids")) <> "" then
		db_string = "delete informacao.tb_usuario_uf_form where cod_usuario="&vcod_usuario&" and cod_form=2;"
		db_string = db_string & "insert into informacao.tb_usuario_uf_form("
		db_string = db_string & "cod_usuario,"
		db_string = db_string & "cod_uf,"
		db_string = db_string & "cod_form "
		db_string = db_string & ") ("
		db_string = db_string & " select "&vcod_usuario&","
		db_string = db_string & " cod_uf,"
		db_string = db_string & " 2 as cod_form "
		db_string = db_string & " from informacao.tb_ufs "
		db_string = db_string & " where cod_uf in("&request("ids")&")"
		db_string = db_string & ")"
		executeQuery(db_string)
	else
		db_string = "delete informacao.tb_usuario_uf_form where cod_usuario="&vcod_usuario&" and cod_form=2;"
		executeQuery(db_string)
	End if
	response.write "{success : true,data :{}}"
End Sub

Sub setDDD()
	Dim db_string
	if trim(request("ids")) <> "" then
		db_string = "delete informacao.tb_usuario_ddd_form where cod_usuario="&vcod_usuario&" and cod_form=2;"
		db_string = db_string & "insert into informacao.tb_usuario_ddd_form("
		db_string = db_string & "cod_usuario,"
		db_string = db_string & "cod_ddd,"
		db_string = db_string & "cod_form "
		db_string = db_string & ") ("
		db_string = db_string & " select "&vcod_usuario&","
		db_string = db_string & " cod_ddd,"
		db_string = db_string & " 2 as cod_form "
		db_string = db_string & " from informacao.tb_ddds "
		db_string = db_string & " where cod_ddd in("&request("ids")&")"
		db_string = db_string & ")"
		executeQuery(db_string)
	else
		db_string = "delete informacao.tb_usuario_ddd_form where cod_usuario="&vcod_usuario&" and cod_form=2;"
		executeQuery(db_string)
	End if
	response.write "{success : true,data :{}}"
End Sub

Sub setArea()
	Dim db_string
	if trim(request("ids")) <> "" then
		db_string = "delete informacao.tb_usuario_area_form where cod_usuario="&vcod_usuario&" and cod_form=2;"
		db_string = db_string & "insert into informacao.tb_usuario_area_form("
		db_string = db_string & "cod_usuario,"
		db_string = db_string & "cod_area,"
		db_string = db_string & "cod_form "
		db_string = db_string & ") ("
		db_string = db_string & " select "&vcod_usuario&","
		db_string = db_string & " cod_area,"
		db_string = db_string & " 2 as cod_form "
		db_string = db_string & " from informacao.tb_areas "
		db_string = db_string & " where cod_area in("&request("ids")&")"
		db_string = db_string & ")"
		executeQuery(db_string)
	else
		db_string = "delete informacao.tb_usuario_area_form where cod_usuario="&vcod_usuario&" and cod_form=2;"
		executeQuery(db_string)
	End if
	response.write "{success : true,data :{}}"
End Sub

Sub setCargo()
	Dim db_string
	if trim(request("ids")) <> "" then
		db_string = "delete informacao.tb_usuario_cargo_form where cod_usuario="&vcod_usuario&" and cod_form=2;"
		db_string = db_string & "insert into informacao.tb_usuario_cargo_form("
		db_string = db_string & "cod_usuario,"
		db_string = db_string & "cod_cargo,"
		db_string = db_string & "cod_form "
		db_string = db_string & ") ("
		db_string = db_string & " select "&vcod_usuario&","
		db_string = db_string & " cod_cargo,"
		db_string = db_string & " 2 as cod_form "
		db_string = db_string & " from informacao.tb_cargos "
		db_string = db_string & " where cod_cargo in("&request("ids")&")"
		db_string = db_string & ")"
		executeQuery(db_string)
	else
		db_string = "delete informacao.tb_usuario_cargo_form where cod_usuario="&vcod_usuario&" and cod_form=2;"
		executeQuery(db_string)
	End if
	response.write "{success : true,data :{}}"
End Sub

Sub getComunicados()
	Dim db_string
	Dim pagina
	Dim pagina_funcao
	Dim dt
	writeHeader("")
	db_string = "select  distinct "
	db_string = db_string & "	i.titulo as [Titulo], "
	db_string = db_string & "	ass.desc_assunto as [Assunto], "
	db_string = db_string & "	i.dt_agendamento_envio as [Data envio],"
	db_string = db_string & "	si.desc_status_informativo as [Status],"
	db_string = db_string & " 	case when i.cod_status_informativo in(2,4) then "
	db_string = db_string & "		'<a href='+Char(39)+'#'+Char(39)+' class='+Char(39)+'botao ico'+Char(39)+' title='+Char(39)+'Opções'+Char(39)+' onclick='+Char(39)+'return bi.Menu({el: this, pos: '+Char(34)+'td'+Char(34)+', opcoes: ['+Char(34)+'Passo 1'+Char(34)+', '+Char(34)+'Passo 2'+Char(34)+', '+Char(34)+'Passo 3'+Char(34)+','+Char(34)+'Duplicar'+Char(34)+'], funcao: ['+Char(34)+'buscar('+convert(varchar(20),i.cod_informativo)+',1);'+Char(34)+', '+Char(34)+'buscar('+convert(varchar(20),i.cod_informativo)+',2);'+Char(34)+', '+Char(34)+'buscar('+convert(varchar(20),i.cod_informativo)+',3);'+Char(34)+', '+Char(34)+'btn_duplicar('+convert(varchar(20),i.cod_informativo)+',"&vcod_usuario&");'+Char(34)+']});'+Char(39)+'><span class='+Char(39)+'gear'+Char(39)+'></span></a> "
	db_string = db_string & "    	 <a href='+Char(39)+'relatorios.asp?cod_informativo='+convert(varchar(20),i.cod_informativo)+'&filtro_titulo="&request("filtro_titulo")&"&filtro_assunto="&request("filtro_assunto")&"&filtro_data="&request("filtro_data")&"&sts="&request("cmb_filtro_status")&"&pagina="&request("pagina")&"&origem=c'+Char(39)+' class='+Char(39)+'botao ico'+Char(39)+' title='+Char(39)+'Relatório'+Char(39)+'><span class='+Char(39)+'relatorios'+Char(39)+'></span></a> ' "
	'db_string = db_string & "    	 <a href='+Char(39)+'relatorios.asp?cod_informativo='+convert(varchar(20),i.cod_informativo)+Char(39)+' class='+Char(39)+'botao ico'+Char(39)+' title='+Char(39)+'Relatório'+Char(39)+'><span class='+Char(39)+'relatorios'+Char(39)+'></span></a> ' "
	db_string = db_string & " 	else "
	db_string = db_string & "		'<a href='+Char(39)+'#'+Char(39)+' class='+Char(39)+'botao ico'+Char(39)+' title='+Char(39)+'Opções'+Char(39)+' onclick='+Char(39)+'return bi.Menu({el: this, pos: '+Char(34)+'td'+Char(34)+', opcoes: ['+Char(34)+'Passo 1'+Char(34)+', '+Char(34)+'Passo 2'+Char(34)+', '+Char(34)+'Passo 3'+Char(34)+','+Char(34)+'Duplicar'+Char(34)+'], funcao: ['+Char(34)+'buscar('+convert(varchar(20),i.cod_informativo)+',1);'+Char(34)+', '+Char(34)+'buscar('+convert(varchar(20),i.cod_informativo)+',2);'+Char(34)+', '+Char(34)+'buscar('+convert(varchar(20),i.cod_informativo)+',3);'+Char(34)+', '+Char(34)+'btn_duplicar('+convert(varchar(20),i.cod_informativo)+',"&vcod_usuario&");'+Char(34)+']});'+Char(39)+'><span class='+Char(39)+'gear'+Char(39)+'></span></a>' "
	db_string = db_string & "	end "
	db_string = db_string & "   as [Ações] "
	db_string = db_string & " from informativos.tb_informativos as i "
	db_string = db_string & " inner join informativos.tb_status_informativo as si on si.cod_status_informativo=i.cod_status_informativo "
	db_string = db_string & " inner join informativos.tb_assunto_informativo as ass on ass.cod_assunto_informativo=i.cod_assunto_informativo "

	if request("chk_reg_select") <> "" then
		db_string = db_string & " inner join informativos.tb_informativos_regional as r on r.cod_informativo=i.cod_informativo "
		db_string = db_string & " and r.cod_regional in ("&request("chk_reg_select")&") "
	end if
	if request("chk_uf_select") <> "" then
		db_string = db_string & " inner join informativos.tb_informativos_uf as uf on uf.cod_informativo=i.cod_informativo "
		db_string = db_string & " and uf.cod_uf in ("&request("chk_uf_select")&") "
	end if
	if request("chk_ddd_select") <> "" then
		db_string = db_string & " inner join informativos.tb_informativos_ddd as ddd on ddd.cod_informativo=i.cod_informativo "
		db_string = db_string & " and ddd.cod_ddd in ("&request("chk_ddd_select")&") "
	end if
	if request("chk_area_select") <> "" then
		db_string = db_string & " inner join informativos.tb_informativos_area as area on area.cod_informativo=i.cod_informativo "
		db_string = db_string & " and area.cod_area in ("&request("chk_area_select")&") "
	end if
	if request("chk_cargo_select") <> "" then
		db_string = db_string & " inner join informativos.tb_informativos_cargo as c on c.cod_informativo=i.cod_informativo "
		db_string = db_string & " and c.cod_cargo in ("&request("chk_cargo_select")&") "
	end if

	db_string = db_string & " where 1=1 "	

	if request("cod") <> "" then
		db_string = db_string & " and i.cod_informativo="&request("cod")
	end if

	if request("filtro_titulo") <> "" then
		db_string = db_string & " and i.titulo like '%"&request("filtro_titulo")&"%' "
	end if
	if request("filtro_assunto") <> "" then
		db_string = db_string & " and ass.desc_assunto like '%"&request("filtro_assunto")&"%' "
	end if

	if request("filtro_data") <> "" then
		dt = split(request("filtro_data"),"/")
		db_string = db_string & " and i.dt_agendamento_envio between '"&dt(2)&"-"&dt(1)&"-"&dt(0)&" 00:00:00' and '"&dt(2)&"-"&dt(1)&"-"&dt(0)&" 23:59:59'"
	end if

	if request("cmb_filtro_status") <> "" and request("cmb_filtro_status") <> "Selecione" then
		db_string = db_string & " and i.cod_status_informativo in ("&request("cmb_filtro_status")&") "
	end if

	db_string = db_string & " order by i.dt_agendamento_envio desc "

	if isnumeric(request("pagina")) = true then
		pagina = cdbl(request("pagina"))
	else
		pagina = 1
	end if

	response.write Table("list", db_string, "tabela", true, pagina, 10, "getComunicados(!@#)")
End Sub
%>